package com.Q08;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @version v1.0.0
 * 创建时间：2022/7/29 09:07
 */
public class Q08_07 {
    ArrayList<String> res;
    public String[] permutation(String S) {
        char[] charArray = S.toCharArray();
        res = new ArrayList<>();
        helper(charArray,0);
        String[] strings = res.toArray(new String[]{});
        return strings;
    }

    public void helper(char[] charArray,int cur){
        if (cur==charArray.length){
            res.add(new String(charArray));
            return;
        }
        for (int i = cur; i < charArray.length; i++) {
            swap(charArray,cur,i);
            helper(charArray,cur+1);
            swap(charArray,cur,i);
        }
    }

    private void swap(char[] chars,int i,int j){
        char temp = chars[i];
        chars[i] = chars[j];
        chars[j] = temp;
    }

    public static void main(String[] args) {
        new Q08_07().permutation("qwe");
    }
}
